import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles

from core.docs import custom_api_docs
from core.exception import register_exception

from modules.common import upload

from modules.admin.auth import role

from modules.admin.auth.view import dept
from modules.admin.auth.view import menu

from modules.admin.system.view import dicts

from modules.auth import auth

from modules.sales import home
from modules.sales import category
from modules.sales import banner
from modules.sales import goods
from modules.sales import member

from configs import config

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 允许所有来源
    allow_credentials=True,
    allow_methods=["*"],  # 允许所有方法
    allow_headers=["*"],  # 允许所有头部
)

app.mount("/statics", StaticFiles(directory="statics"), name="statics")

custom_api_docs(app)
register_exception(app)

# common
app.include_router(upload.router)

# admin
app.include_router(menu.router)
app.include_router(role.router)
app.include_router(dept.router)

app.include_router(dicts.router)

# auth
app.include_router(auth.router)

# sales
app.include_router(home.router)
app.include_router(category.router)
app.include_router(banner.router)
app.include_router(goods.router)
app.include_router(member.router)

uvicorn.run(app, host=config.server.host, port=config.server.port, workers=1)
